class @AccountRoutes extends Backbone.Router
    routes:
        "Account/LogOn*path": "LogOn"
        "Account/LogOn": "LogOn"
        "Account/LogOff": "LogOff"
        "Account/Edit*path":"Edit"
        "Account/ShowProfile/:login*path": "ShowProfile"
        "Account/ShowProfileRatedBooks/:login*path": "ShowProfileRatedBooks"

    LogOn: (path)->
        layout = new LibraryLayoutView()
        model = new LogOnModel()
        model.set("ReturnUrl", Url.GetParameterByName("ReturnUrl"))
        view = new LogOnView(model: model)
    
    LogOff: ->
        Loading.Start()
        view = new WelcomView(model: new WelcomModel())
        url = SiteMap.Home.Index
        view.render()
        $.ajax(
            url: SiteMap.Account.LogOff,
            success: ->
                view.Navigate(url, true)
        )

    Edit: (path) ->
        layout = new LibraryLayoutView()
        model = new EditProfileModel()
        view = new EditProfileView({model:model})

    ShowProfile: (login, path) ->
        layout = new LibraryLayoutView()
        model = new ShowProfileModel()
        model.set("Login", login)      
        view = new ShowProfileView({model: model})

    ShowProfileRatedBooks: (login, path) ->
        layout = new LibraryLayoutView()
        model = new ProfileRatedBooksModel()
        model.set("Login", login)

        column = Url.GetParameterByName("Column")
        if column.length
            model.setStaticProperty("Column", column)

        direction = Url.GetParameterByName("Direction")
        if direction.length
            model.setStaticProperty("Direction", parseInt(direction))

        viewType = Url.GetParameterByName("viewType")
        if viewType.length
            model.setStaticProperty("BookViewType", parseInt(viewType))

        view = new ProfileRatedBooksView({model: model})